#include <iostream>
#include <string>
#include <vector>

using namespace std;

class Person {
public:
    Person(string name, int age) {
        this->name = name;
        this->age = age;
    }

    Person() {}

    string getName() {
        return this->name;
    }

    int getAge() {
        return this->age;
    }

    void setName(string name) {
        this->name = name;
    }

    void setAge(int age) {
        this->age = age;
    }
    
private:
    string name;
    int age;
};

void createPeople(vector<Person> &people) {
    Person person1("John", 25);
    Person person2("Jane", 30);
    Person person3("Bob", 35);

    people.push_back(person1);
    people.push_back(person2);
    people.push_back(person3);

    people.push_back(Person("Alice", 28));
}

void printPeople(vector<Person> &people) {
    for (vector<Person>::iterator it = people.begin(); it != people.end(); it++) {
        cout << "Name: " << it->getName() << ", Age: " << it->getAge() << endl;
    }
}

void createPeople(vector<Person*> &people) {
    Person person1("John", 25);
    Person person2("Jane", 30);
    Person person3("Bob", 35);

    people.push_back(&person1);
    people.push_back(&person2);
    people.push_back(&person3);

}

void printPeople(vector<Person*> &people) {
    for (vector<Person*>::iterator it = people.begin(); it != people.end(); it++) {
        Person *p = *it;
        cout << "Name: " << p->getName() << ", Age: " << p->getAge() << endl;
    }
}

/**
 * 存放自定义数据类型Person
 */
void test01() {
    vector<Person> people;

    createPeople(people);

    printPeople(people);
}

/**
 * 存放自定义数据类型Person的指针
 */
void test02() {
    vector<Person*> people;

    createPeople(people);

    printPeople(people);
}

/**
 * 存放自定义数据类型Person的指针
 */
void test03() {
    vector<Person*> v;

	//创建数据
	Person p1("aaa", 10);
	Person p2("bbb", 20);
	Person p3("ccc", 30);
	Person p4("ddd", 40);
	Person p5("eee", 50);

	v.push_back(&p1);
	v.push_back(&p2);
	v.push_back(&p3);
	v.push_back(&p4);
	v.push_back(&p5);

	for (vector<Person*>::iterator it = v.begin(); it != v.end(); it++) {
		Person * p = (*it);
		cout << "Name:" << p->getName() << " Age:" << (*it)->getAge() << endl;
	}
}

int main() {

    test02();

    return 0;
}